Developer Documentation

QuickTime 4 API Documentation

QuickTime 4 Reference

| Previous | Chapter Contents | Chapter Top | Next |

Creating a tween sample

Listing 2 Creating a tween sample

QTAtomContainer container = nil;
short tweenDataShort[2];
QTAtomType tweenType;

tweenDataShort[0] = EndianS16_NtoB(255);
tweenDataShort[1] = EndianS16_NtoB(0);

// create a new atom container to hold the sample
QTNewAtomContainer (&container);

// create the parent tween entry atom
QTInsertChild (container, kParentAtomIsContainer, kTweenEntry, 1, 0, 0,
    nil, &tweenAtom);

// add two child atoms to the tween entry atom
// * the type atom, kTweenType
tweenType = EndianU32_NtoB(kTweenTypeShort);
QTInsertChild (container, tweenAtom, kTweenType, 1, 0,
    sizeof(tweenType), &tweenType, nil);

// * the data atom, kTweenData
QTInsertChild (container, tweenAtom, kTweenData, 1, 0, sizeof(short) * 2,
    tweenDataShort, nil);

You do not have to start the tween at the beginning of the sample, nor do you have to stop at the end of the sample. You can specify the start of the tween and its duration by adding additional child atoms to the tween entry.

Figure 2 illustrates, for example, how you can use tween media to modify a sound track's volume. The first part of the illustration shows an example of tweening the sound volume from 0 to 255, with the tween offset at 0 and the tween duration at 100. In the second part, with the tween offset at 25 and the duration at 50, the tween has no effect until time 25--after which it causes the volume to fade in over the next 50 time units. The volume is left at 255. The third part shows the tween offset at 25 and the tween duration at 100. Since the offset plus the duration of this tween is greater than the duration of the tween media sample, the sound track never reaches full volume.

Figure 2 Using tween media to modify the sound track's volume

You can add a kTweenStartOffset atom to start the tween operation at 500 units into the sample with the following lines of code:

TimeValue time = EndianU32_NtoB(500);
QTInsertChild (container, tweenAtom, kTweenStartOffset, 1, 0,
    sizeof(TimeValue), &time, nil);

You can specify a duration for the tween operation independent of the sample's duration by adding a kTweenDuration atom to the tween entry, as follows:

TimeValue duration = EndianU32_NtoB(1000);
QTInsertChild (container, tweenAtom, kTweenDuration, 1, 0,
    sizeof(TimeValue), &duration, nil);

Once the tween samples have been created, you can add them to the tween media and then add the tween media to the track, as shown in Listing 3 .


© 1999 Apple Computer, Inc.

| Previous | Chapter Contents | Chapter Top | Next |